package main

import (
	"net/http"

	"git.oschina.net/dddailing/annotate/server"
	"github.com/dailing/levlog"
)

func main() {
	http.Handle("/", http.RedirectHandler("/static/index.html", 303))
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
	http.Handle("/asserts/", http.StripPrefix("/asserts/", http.FileServer(http.Dir("asserts"))))

	app := server.NewApp()
	app.Init()

	http.Handle("/api/get_token", server.HandleReq(server.BodyToJson, app.HandleToken))

	http.Handle("/api/getimg/", http.StripPrefix("/api/getimg/",
		server.HandleReq(app.RequireToken, app.HandleImage)))

	http.Handle("/api/add_annotation", server.HandleReq(app.RequireToken, app.HandleAddAnnotation))
	http.Handle("/api/get_done", server.HandleReq(app.RequireToken, app.HandleGetAnnotationList))

	http.Handle("/api/add_img", server.HandleReq(app.RequireToken, app.HandleAddImage))
	http.Handle("/api/get_list", server.HandleReq(
		app.RequireToken,
		app.RequireUserInfo,
		server.BodyToJson,
		app.HandleImageList))
	http.Handle("/api/add_patient", server.HandleReq(app.RequireToken, app.HandleAddPatient))
	http.Handle("/api/add_session", server.HandleReq(app.RequireToken, app.HandleAddSession))
	http.Handle("/api/get_session", server.HandleReq(app.RequireToken, server.BodyToJson, app.HandleGetSession))
	http.Handle("/api/add_img_to_session", server.HandleReq(app.RequireToken, app.HandleAddImageToSession))
	levlog.Info("Start")
	levlog.Fatal(http.ListenAndServe(":8080", nil))
}
